function varargout = MEMC_MATScaleWnd(varargin)
% MEMC_MATSCALEWND M-file for MEMC_MATScaleWnd.fig
%      MEMC_MATSCALEWND, by itself, creates a new MEMC_MATSCALEWND or raises the existing
%      singleton*.
%
%      H = MEMC_MATSCALEWND returns the handle to a new MEMC_MATSCALEWND or the handle to
%      the existing singleton*.
%
%      MEMC_MATSCALEWND('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in MEMC_MATSCALEWND.M with the given input arguments.
%
%      MEMC_MATSCALEWND('Property','Value',...) creates a new MEMC_MATSCALEWND or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before MEMC_MATScaleWnd_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to MEMC_MATScaleWnd_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help MEMC_MATScaleWnd

% Last Modified by GUIDE v2.5 26-Jul-2010 14:53:36

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @MEMC_MATScaleWnd_OpeningFcn, ...
                   'gui_OutputFcn',  @MEMC_MATScaleWnd_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);

if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end
    
if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before MEMC_MATScaleWnd is made visible.
function MEMC_MATScaleWnd_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to MEMC_MATScaleWnd (see VARARGIN)

handles.TypeMode = 0;
if nargin && isequal(varargin{1},'TypeName')
   set(handles.tagMATScaleText,'String',varargin{2});
   tmpScaleType = varargin{3};
   if tmpScaleType == 1
       set(handles.tagScaleName1,'String','Data Scale:');
       set(handles.tagScaleName2,'String','Scald');
       set(handles.tagScaleName3,'Visible','off');
       set(handles.tagScaleValue2,'Visible','off');
       handles.TypeMode = 1;
   elseif tmpScaleType == 2
       set(handles.tagScaleName1,'String','Vector Scale:');
       set(handles.tagScaleName2,'String','Scaly');
       set(handles.tagScaleName3,'String','Scaluv');
       handles.TypeMode = 2;
   else 
      set(handles.tagScaleName1,'Visible','off');
      set(handles.tagScaleName2,'Visible','off');
      set(handles.tagScaleName3,'Visible','off');
      set(handles.tagScaleValue1,'Visible','off'); 
      set(handles.tagScaleValue2,'Visible','off'); 
   end
   handles.scale   = varargin{4};
   handles.blend   = varargin{5};
   handles.blendEn = varargin{6};
   
   if handles.blendEn == 0
      set(handles.tagBlendText1,'Visible','off');
      set(handles.tagBlendText2,'Visible','off');
      set(handles.tagBlendText3,'Visible','off');
      set(handles.tagBlendText4,'Visible','off');
      set(handles.tagBlendEdit1,'Visible','off');
      set(handles.tagBlendEdit2,'Visible','off');
      set(handles.tagBlendEdit3,'Visible','off'); 
   end
end

% Choose default command line output for MEMC_MATScaleWnd
if handles.TypeMode == 1 && ~isempty(handles.scale)
   str = sprintf('%g',handles.scale);
   set(handles.tagScaleValue1,'String',str);
elseif handles.TypeMode == 2 && ~isempty(handles.scale)
   str = sprintf('%g',handles.scale(1));
   set(handles.tagScaleValue1,'String',str);
   str = sprintf('%g',handles.scale(2));
   set(handles.tagScaleValue2,'String',str);
end

%blend
if handles.blendEn == 1 && ~isempty(handles.blend)
   str = sprintf('%g',handles.blend(1));
   set(handles.tagBlendEdit1,'String',str);
   str = sprintf('%g',handles.blend(2));
   set(handles.tagBlendEdit2,'String',str);
   str = sprintf('%g',handles.blend(3));
   set(handles.tagBlendEdit3,'String',str);
end

handles.scale_prev = handles.scale;
handles.blend_prev = handles.blend;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes MEMC_MATScaleWnd wait for user response (see UIRESUME)
uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = MEMC_MATScaleWnd_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Get default command line output from handles structure
varargout{1} = handles.scale;
varargout{2} = handles.blend;
delete(handles.figure1);


function tagScaleValue1_Callback(hObject, eventdata, handles)
% hObject    handle to tagScaleValue1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of tagScaleValue1 as text
%        str2double(get(hObject,'String')) returns contents of tagScaleValue1 as a double
handles.scale(1) = str2double(get(hObject,'String'));
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function tagScaleValue1_CreateFcn(hObject, eventdata, handles)
% hObject    handle to tagScaleValue1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


function tagScaleValue2_Callback(hObject, eventdata, handles)
% hObject    handle to tagScaleValue2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of tagScaleValue2 as text
%        str2double(get(hObject,'String')) returns contents of tagScaleValue2 as a double
handles.scale(2) = str2double(get(hObject,'String'));
guidata(hObject, handles);

% --- Executes during object creation, after setting all properties.
function tagScaleValue2_CreateFcn(hObject, eventdata, handles)
% hObject    handle to tagScaleValue2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on button press in pushbutton1.
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
uiresume(handles.figure1);


% --- Executes when user attempts to close figure1.
function figure1_CloseRequestFcn(hObject, eventdata, handles)
% hObject    handle to figure1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% Hint: delete(hObject) closes the figure
handles.scale = handles.scale_prev;
handles.blend = handles.blend_prev;
guidata(hObject, handles);
uiresume(hObject);


function tagBlendEdit1_Callback(hObject, eventdata, handles)
% hObject    handle to tagBlendEdit1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of tagBlendEdit1 as text
%        str2double(get(hObject,'String')) returns contents of tagBlendEdit1 as a double
handles.blend(1) = str2double(get(hObject,'String'));
guidata(hObject, handles);


function tagBlendEdit2_Callback(hObject, eventdata, handles)
% hObject    handle to tagBlendEdit2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of tagBlendEdit2 as text
%        str2double(get(hObject,'String')) returns contents of tagBlendEdit2 as a double
handles.blend(2) = str2double(get(hObject,'String'));
guidata(hObject, handles);


function tagBlendEdit3_Callback(hObject, eventdata, handles)
% hObject    handle to tagBlendEdit3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of tagBlendEdit3 as text
%        str2double(get(hObject,'String')) returns contents of tagBlendEdit3 as a double
handles.blend(3) = str2double(get(hObject,'String'));
guidata(hObject, handles);

